package com.example.test3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Controller
@CrossOrigin(origins = "*")
public class DataController {
    @Autowired
    DataService service;
    List<RegionStates> list;

    @GetMapping("/all")
    @ResponseBody
    public List<RegionStates> getAll() throws IOException {
        list = service.getAll();
        return list;
    }

    @GetMapping("/searchByState/{state}")
    @ResponseBody
    public List<RegionStates> searchByState(@PathVariable("state")String state)throws IOException{
        list = service.getByState(state);
        return list;
    }

    @GetMapping("/searchByCountry/{country}")
    @ResponseBody
    public List<RegionStates> searchByCountry(@PathVariable("country")String country)throws IOException{
        list = service.getByCountry(country);
        return list;
    }
}
